import os
import sys
import re
import optparse



def main():
    fileName = r'..\data\combat_2012-04-29_17_10_11_437005_short.txt'
    inFile = open(fileName)
    
    
    regEx = re.compile(r"""
        (\[                     #timeStamp Opening Bracket
            (\d{2,2}):          #timeStamp.hour
            (\d{2,2}):          #timeStamp.minute
            (\d{2,2})[.]        #timeStamp.second
            (\d{3,3})           #timeStamp.millisecond
        \])\                    #timeStamp Ending Bracket
        
        (\[                     #initiatingActor Opening Bracket
            @?
            ([a-zA-Z' ]*)       #initiatingActor.name
            :?                  
            ([a-zA-Z ]*)        #initiatingActor.companionName
            \{?
            (\d*)               #initiatingActor.UID
            \}?
        \])\                    #initiatingActor Ending Bracket
        
        (\[                     #affectedActor Opening Bracket
            @?
            ([a-zA-Z' ]*)       #affectedActor.name
            :?                  
            ([a-zA-Z ]*)        #affectedActor.companionName
            \{?
            (\d*)               #affectedActor.companion.UID
            \}?
        \])\                    #affectedActor Ending Bracket
        
        (\[                     #action Opening Bracket
            ([a-zA-Z' \(\)]*)   #action.name
            (\{?
            (\d*)               #action.UID
            \})?
        \])\                    #action Ending Bracket
        
        (\[                     #event Opening Bracket
            ([a-zA-Z' \(\)]*)   #event.name
            {
            (\d*)               #event.UID
            }:\                 
            ([a-zA-Z' \(\)]*)   #event.type.name
            {
            (\d*)               #event.type.UID
            }
        \])\                    #event Ending Bracket
        
        (\(                     #value Opening Bracket
            (\d*)\ ?            #value.value
            ([a-zA-Z ]*)        #value.damageType
            \{?
            (\d*)               #value.damageTypeUID
            \}?
        \))\ ? 
        
        (
            <?(\d*)>?          #result
        )
        """, re.VERBOSE)
    
    
    #regEx = re.compile('(\[[^\]]*\] ){5,5}(\([^\)]*\))(.*$)')
    
    for line in inFile:
        print regEx.match(line).groups()
    
    '''
    regEx = re.compile('\[[^\]]*\]')
    
    for line in inFile:
        lineContents = regEx.findall(line)
        timeStamp = lineContents[0]
        initiatingActor = lineContents[1]
        targetingActor = lineContents[2]
        abilityName = lineContents[3]
        effectResult = lineContents[4]
        
        print "timeStamp = %s\ninitiatingActor = %s" % (timeStamp, initiatingActor)
        print "targetingActor = %s\nabilityName = %s" % (targetingActor, abilityName)
        print "effectResult = %s\n" % (effectResult)
    '''


if __name__  == '__main__' :
    main()